'''
遇到问题没人解答？小编创建了一个Python学习交流QQ群：778463939
寻找有志同道合的小伙伴，互帮互助,群里还有不错的视频学习教程和PDF电子书！
'''
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from collections import Counter

# Generate some data
X, y = make_blobs(n_samples=400, centers=4, cluster_std=0.60, random_state=0)

print(X)
print(y)

# kmeans clustering
kmeans = KMeans(5, random_state=0)
kmeans.fit(X)  # 训练模型
labels = kmeans.predict(X)  # 预测分类

count = Counter(labels)
print(count)

plt.scatter(X[:, 0], X[:, 1], c=labels, s=40, cmap='viridis')
plt.show()
